package com.lk.recvice.handler;

import com.lk.recvice.handler.impl.DatasManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class OtaManagerBuilder {

	private static OtaManagerBuilder instance = new OtaManagerBuilder();

	public static OtaManagerBuilder getInstance() {
		return instance;
	}


	private Map<String, OtaManager> otaManagerRegistry;

	 @Autowired
	 private OtaManagerBuilder() {
		 if(otaManagerRegistry == null ) {
			 otaManagerRegistry = new HashMap<>();
		 }
		 otaManagerRegistry.put("datas",new DatasManager());
	 }

	 public OtaManager build(String handleType) {
		 try {

			 OtaManager manager = otaManagerRegistry.get(handleType);

			 if (manager != null) {
				 return manager;
			 }
		} catch (Exception e) {
			throw new RuntimeException(handleType + ":无法识别的处理类型");
		}
		 throw new RuntimeException(handleType + ":无法识别的处理类型");

	 }

}
